package com.ly.honor.controller;



import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ly.honor.entity.Match;
import com.ly.honor.entity.dto.GameQueryDTO;
import com.ly.honor.entity.dto.MatchCreateDTO;
import com.ly.honor.entity.dto.MatchEditDTO;
import com.ly.honor.entity.dto.MatchQueryDTO;
import com.ly.honor.entity.vo.MatchQueryVO;
import com.ly.honor.service.MatchService;
import com.ly.honor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

/**
 * (Match)表控制层
 *
 * @author makejava
 * @since 2022-11-16 11:53:59
 */
@RestController
@RequestMapping("match")
@Api(tags = "比赛管理")
public class MatchController  {
    /**
     * 服务对象
     */
    @Resource
    private MatchService matchService;

    /**
     *
     * @param pageNum
     * @param pageSize
     * @param matchQueryDTO
     * @return
     */
    @ApiOperation("分页查询所有数据")
    @PostMapping("selectMatchPage/{pageNum}/{pageSize}")
    public Result selectMatchPage(@PathVariable("pageNum") long pageNum,
                                  @PathVariable("pageSize") long pageSize,
                                  @RequestBody(required = false) MatchQueryDTO matchQueryDTO) {
        Page<MatchQueryVO> matchQueryVOPage =   matchService.selectMatchPage(pageNum,pageSize,matchQueryDTO);
        return Result.ok(matchQueryVOPage);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("getMatchById/{id}")
    public Result getMatchById(@PathVariable long id) {
        MatchQueryVO matchQueryVO = matchService.getMatchById(id);
        return Result.ok(matchQueryVO);
    }

    /**
     * 新增数据
     *
     * @param matchCreateDTO 实体对象
     * @return 新增结果
     */
    @ApiOperation("新增比赛")
    @PostMapping("insertMatch")
    public Result insertMatch(@RequestBody @Valid MatchCreateDTO matchCreateDTO) {
        matchService.insertMatch(matchCreateDTO);
        return Result.ok();
    }

    /**
     * 修改比赛数据
     *
     * @param matchEditDTO 实体对象
     * @return 修改结果
     */
    @ApiOperation("修改比赛数据")
    @PostMapping("updateMatch")
    public Result updateMatch(@RequestBody @Valid MatchEditDTO matchEditDTO) {
        matchService.updateMatch(matchEditDTO);
        return Result.ok();
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("deleteMatchById/{id}")
    public Result deleteMatchById(@PathVariable long id) {
        matchService.removeById(id);
        return Result.ok();
    }

    @DeleteMapping("removeBatch")
    public Result removeBatch(@RequestBody List<Long> idList) {
        matchService.removeByIds(idList);
        return Result.ok();
    }

    @ApiOperation("根据时间进行查询比赛")
    @PostMapping("getMatchByTime")
    public Result getMatchByTime(@RequestBody JSONObject json) {
        var time = json.getString("time");
        List<MatchQueryVO> matchQueryVOList = matchService.getMatchByTime(time);
        return Result.ok(matchQueryVOList);
    }
}

